﻿<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:controls="clr-namespace:System.Controls">

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Common.xaml"/>
  </ResourceDictionary.MergedDictionaries>

  
  <ControlTemplate x:Key="controlTemplate" TargetType="controls:RadioButton">

    <Border 
      x:Name="border" 
      BorderThickness="{TemplateBinding BorderThickness}" 
      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
      Background="{TemplateBinding Background}"
      BorderBrush="{TemplateBinding BorderBrush}">

      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition x:Name="leftColumn" Width="Auto"/>
          <ColumnDefinition x:Name="rightColumn" />
        </Grid.ColumnDefinitions>

        <Grid x:Name="bulletGridCheck" 
      		Width="15" 
      		Height="15">

          <Ellipse 
			      x:Name="PART_outer" 
			      Stroke="{StaticResource BulletBorder}"/>

          <Ellipse 
			      x:Name="PART_inner" 
			      Margin="2" 
			      Fill="{StaticResource BulletInnerFill}"/>

          <Ellipse 
			      x:Name="uncheckedAltVisualization" 
			      Visibility="Hidden" 
			      Margin="2"
      		  Fill="{StaticResource AltUnCheckedBulletFill}"/>

          <Ellipse 
			      x:Name="checkedVisualization" 
			      Visibility="Hidden" 
			      Margin="2"
			      Fill="{StaticResource CheckedBulletFill}"/>

        </Grid>

        <ContentPresenter
          x:Name="content"
		      Grid.Column="1"
          RecognizesAccessKey="True"
          Margin="{TemplateBinding Padding}" 
		      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
		      VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
          Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=HasContent, Converter={StaticResource b2v}}" >
          <ContentPresenter.Content>
            <TextBlock
		          Text="{TemplateBinding Content}"
		          TextWrapping="{TemplateBinding TextWrapping}" 
              MaxWidth="{TemplateBinding TextWidth}"/>
          </ContentPresenter.Content>
        </ContentPresenter>

      </Grid>

    </Border>

    <ControlTemplate.Triggers>
      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="BulletDock" Value="Left"/>
          <Condition Property="HasContent" Value="True"/>
        </MultiTrigger.Conditions>
        <Setter Property="Padding" Value="4,0,0,0"/>
        <Setter Property="SharedSizeGroup" Value="{Binding SharedSizeGroup, RelativeSource={RelativeSource TemplatedParent}}" TargetName="rightColumn"/>
        <Setter Property="SharedSizeGroup" Value="{x:Null}" TargetName="leftColumn" />
        <Setter Property="Width" Value="Auto" TargetName="leftColumn"/>
        <Setter Property="Width" Value="*" TargetName="rightColumn" />
        <Setter Property="Grid.Column" Value="0"   TargetName="bulletGridCheck"/>
        <Setter Property="Grid.Column" Value="1"   TargetName="content"/>
      </MultiTrigger>

      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="BulletDock" Value="Right"/>
          <Condition Property="HasContent" Value="True"/>
        </MultiTrigger.Conditions>
        <Setter Property="Padding" Value="4,0,0,0"/>
        <Setter Property="SharedSizeGroup" Value="{x:Null}" TargetName="leftColumn"/>
        <Setter Property="Width" Value="*" TargetName="leftColumn"/>

        <Setter Property="Width" Value="Auto" TargetName="rightColumn"/>
        <Setter Property="SharedSizeGroup" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SharedSizeGroup}" TargetName="rightColumn"/>

      
        <Setter Property="Grid.Column" Value="0" TargetName="content"/>
        <Setter Property="Grid.Column" Value="1" TargetName="bulletGridCheck"/>
        <Setter Property="HorizontalAlignment" TargetName="content" Value="Right"/>

      </MultiTrigger>


      <Trigger Property="IsMouseOver" Value="True">
        <Setter Property="Background" TargetName="border" 
                Value="{Binding Path=Background,  Converter={StaticResource bc},  ConverterParameter={StaticResource bt0},  Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>
      </Trigger>

      <Trigger Property="IsChecked" Value="True">
        <Setter Property="BorderBrush" TargetName="border" 
                Value="{Binding Path=BorderBrush, Converter={StaticResource bc}, ConverterParameter={StaticResource bt1}, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>

        <Setter Property="Background" TargetName="border" 
                Value="{Binding Path=Background, ConverterParameter={StaticResource bt1}, Converter={StaticResource bc}, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}"/>

        <Setter Property="Visibility" TargetName="checkedVisualization" Value="Visible"/>

      </Trigger>

      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="IsChecked" Value="False"/>
          <Condition Property="IsAlternateUnchecked" Value="True"/>
        </MultiTrigger.Conditions>

        <Setter Property="Visibility" TargetName="uncheckedAltVisualization" Value="Visible"/>

      </MultiTrigger>

    </ControlTemplate.Triggers>

  </ControlTemplate>



  <Style TargetType="{x:Type controls:RadioButton}" BasedOn="{StaticResource {x:Type Control}}">

    <Setter Property="TextWrapping" Value="Wrap"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisualCheck}"/>
    <Setter Property="Template" Value="{StaticResource controlTemplate}"/>

  </Style>

</ResourceDictionary>